package so.shanku.essential.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import aym.util.getservicesdata.GetServicesDataQueue;
import aym.util.getservicesdata.GetServicesDataUtil;
import aym.util.json.JsonMap;
import aym.util.json.JsonParseHelper;
import net.tsz.afinal.annotation.view.ViewInject;
import so.shanku.essential.R;
import so.shanku.essential.activity.base.BaseUIActivity;
import so.shanku.essential.getdata.GetDataConfing;
import so.shanku.essential.getdata.GetDataQueue;
import so.shanku.essential.getdata.JsonKeys;
import so.shanku.essential.getdata.ShowGetDataError;

import java.util.List;

/**
 * Created by Administrator on 2015/9/21.
 */
public class ContactUsActivity extends BaseUIActivity {
    /**
     * 拨打电话
     */
    @ViewInject(id=R.id.linear_call_phone,click = "call_phone_click")
    private LinearLayout linear_call_phone;
    /**
     * 手机号
     */
    @ViewInject(id=R.id.tv_phone_number)
    private TextView tv_phone_number;
    /**
     * 用来点击邮箱
     */
    @ViewInject(id=R.id.linear_send_email,click = "send_email")
    private LinearLayout linear_send_email;
    /**
     * 邮箱
     */
    @ViewInject(id=R.id.tv_email)
    private TextView tv_email;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_us);
        initActivity(true, R.drawable.back, null, R.string.my_contact_us, -1, null);
        getData_ContactUs();
    }
    public void call_phone_click(View view){
        startTelPhone(phone);
    }
    /**
     * 联系我们接口
     */
    private void getData_ContactUs() {
        loadingToast.show();
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.Action_GetContact_Us);
        queue.setCallBack(callBack);
        queue.setParams(null);
        queue.setWhat(GetDataConfing.What_GetContact_Us);
        getDataUtil.getData(queue);
    }
    public void send_email(View view){
        Intent data=new Intent(Intent.ACTION_SENDTO);
        data.setData(Uri.parse("mailto:"+email));
        data.putExtra(Intent.EXTRA_SUBJECT,"标题");
        data.putExtra(Intent.EXTRA_TEXT,"内容");
        startActivity(data);
    }
    private String email;
    private String phone;
    /**
     * 获取服务器数据的返回信息
     */
    private GetServicesDataUtil.IGetServicesDataCallBack callBack = new GetServicesDataUtil.IGetServicesDataCallBack() {
        @Override
        public void onLoaded(GetServicesDataQueue entity) {
            if (entity.isOk()) {

                if (ShowGetDataError.isOkAndCodeIsNot1(ContactUsActivity.this,
                        entity.getInfo())) {
                    List<JsonMap<String, Object>> data = JsonParseHelper.getJsonMap_List_JsonMap(
                            entity.getInfo(), JsonKeys.Key_Info);

                    if (entity.what == GetDataConfing.What_GetContact_Us) {
                        phone=data.get(0).getStringNoNull("contactphone") ;
                        email=data.get(0).getStringNoNull("contactemail") ;
                        tv_phone_number.setText(phone);
                        tv_email.setText(email);
                    }
                }
            } else {
                ShowGetDataError.showNetError(ContactUsActivity.this);
            }
            loadingToast.dismiss();

        }
    };
}
